# Null distribution

source("code/01-importdata.R")
source("code/02-mainresults.R")
source("code/05-emdat.R")
source("code/06-subnational.R")

#### Histogram of t-statistics ####

# bind_rows(results_trends, results_emdat, results_us_trends) %$% median(t_stat) # 0.0627898

rbind(results_trends, results_emdat, results_us_trends) %>% 
  select(t_stat) %>% 
  ggplot(., aes(t_stat)) +
  geom_histogram(aes(y =..density..),
                 # binwidth = 0.2,
                 breaks = c(seq(-5,0,0.25),seq(0.25,5,0.25)),
                 fill = "grey80") +
  # geom_line(aes(y = ..density.., colour = 'Empirical'), stat = 'density',
  #           linetype = 1, 
  #           size = 2, 
  #           color = "grey50") +  
  stat_function(fun = dnorm, args = list(mean = 0, sd = 1),
                linetype = 1,
                color = "#344d0e",
                size = 2) +
  geom_vline(xintercept = 0.0627898, # bind_rows(...) %$% median(t_stat) 
             color = c("black"),
             size = c(2),
             linetype = 2) +
  geom_vline(xintercept = c(-2.84, -1.96, 1.96, 2.84),
             color = c("#79b321", "#456613", "#456613", "#79b321"),
             size = c(2, 1.5, 1.5, 2)) +
  scale_x_continuous(limits = c(-4.8,4.8),
                     breaks = seq(-4,4,1)) +
  labs(x="T-statistics", 
       y="Density") +
  theme_tufte(base_family = "Helvetica") +
  theme(legend.position = "none",
        panel.background = element_rect(fill=NA),
        # panel.grid.major.x = element_line(colour = "grey90"),
        # panel.grid.minor.x = element_line(colour = "grey90"),
        # panel.grid.major.y = element_line(colour = "grey90"),
        panel.ontop = FALSE,
        text=element_text(size=16))
ggsave("text/t_stat_trends.pdf", units = "in", height = 6, width = 10)


